import { K2DU } from "@coldcloude/kai2";
import { KKP2D, KKSize, KKSpriteAnimeCollectionInfo } from "@coldcloude/kakera"

export const SF_B_INVALID = "block_invalid";
export const SF_B_VALID = "block_valid";
export const SF_B_USED = "block_used";

export const SN_1G = "1g";
export const SN_V2G = "v2g";
export const SN_H2G = "h2g";

export const TN_PISTOL = "pistol";
export const TN_SHOTGUN = "shotgun";

export const MN_NORM1 = "norm1";

export const POSGEN_RANDOM = "random";

export function stageName(level:number,stage:number){
    return level+"-"+stage;
}

export type GCTD_TW_CFG = {
    shape: KKP2D[],
    attacks: number[],
    defenses: number[],
    intervals: number[],
    bulletName: string[],
    bulletIntervals: number[],
    bulletVelocities: number[],
    bulletRotateLists: number[][]
};

export type GCTD_MOB_CFG = {
    attack: number,
    defense: number,
    interval: number,
    movement: number,
    energy: number,
    dyingLimit: number
};

export type GCTD_SG_PH_BT_CFG = {
    start: number,
    interval: number,
    mob: string,
    total: number,
    initRectPosition:KKP2D,
    initRectSize:KKSize,
    initXGenerator: string,
    initYGenerator: string,
};

export type GCTD_SG_PH_CFG = {
    maxDuration: number,
    batches: GCTD_SG_PH_BT_CFG[]
};

export type GCTD_SG_CFG = {
    phases: GCTD_SG_PH_CFG[],
    gold: number
}

export const GCTD_CFG = {
    shapes: {} as {[key:string]:KKP2D[]},
    towers: {} as {[key:string]:GCTD_TW_CFG},
    mobs: {} as {[key:string]:GCTD_MOB_CFG},
    stages: {} as {[key:string]:GCTD_SG_CFG}
}

GCTD_CFG.shapes[SN_1G] = [
    {x:0,y:0}
];
GCTD_CFG.shapes[SN_V2G] = [
    {x:0,y:0},
    {x:0,y:1}
];
GCTD_CFG.shapes[SN_H2G] = [
    {x:0,y:0},
    {x:1,y:0}
];

GCTD_CFG.towers[TN_PISTOL] = {
    shape: [
        {x:0,y:0}
    ],
    attacks: [10,20,30,40,50],
    defenses: [100,200,300,400,500],
    intervals: [100,90,80,70,60],
    bulletName: ["","","","",""],
    bulletIntervals: [0,0,0,0,0],
    bulletVelocities: [50,50,50,50,50],
    bulletRotateLists: [[0],[0],[0],[0],[0]]
};
GCTD_CFG.towers[TN_SHOTGUN] = {
    shape: [
        {x:0,y:0},
        {x:0,y:1}
    ],
    attacks: [5,10,15,20,25,30],
    defenses: [100,200,300,400,500],
    intervals: [100,90,80,70,60],
    bulletName: ["","","","",""],
    bulletIntervals: [0,0,0,0,0],
    bulletVelocities: [50,50,50,50,50],
    bulletRotateLists: [
        [0,-Math.PI/6,Math.PI/6],
        [0,-Math.PI/6,Math.PI/6],
        [0,-Math.PI/8,Math.PI/8,-Math.PI/4,Math.PI/4],
        [0,-Math.PI/8,Math.PI/8,-Math.PI/4,Math.PI/4],
        [0,-Math.PI/9,Math.PI/9,-Math.PI*2/9,Math.PI*2/9,-Math.PI/3,Math.PI/3]
    ]
};

GCTD_CFG.mobs[MN_NORM1] = {
    attack: 1,
    defense: 3,
    interval: 1,
    movement: 5,
    energy: 1,
    dyingLimit: 1
};

GCTD_CFG.stages[stageName(1,1)] = {
    phases: [
        {
            maxDuration: 60,
            batches: [
                {
                    start: 2,
                    interval: 0.3,
                    mob: MN_NORM1,
                    total: 10,
                    initRectPosition: {
                        x: 1130,
                        y: 520,
                    },
                    initRectSize: {
                        width: 100,
                        height: 400,
                    },
                    initXGenerator: POSGEN_RANDOM,
                    initYGenerator: K2DU.EF_LINEAR,
                }
            ]
        }
    ],
    gold: 15
};

export type GCTD_E_CFG_UI = {
    animes: KKSpriteAnimeCollectionInfo,
    collision: KKSize
    center: KKP2D,
}

export const GCTD_CFG_UI = {
    block: {
        tileWidth: 100,
        tileHeight: 100,
        sprites: [SF_B_INVALID,SF_B_VALID,SF_B_USED]
    },
    towers: {} as {[key:string]:GCTD_E_CFG_UI[]},
    mobs: {}  as {[key:string]:GCTD_E_CFG_UI},
    bullets: {}  as {[key:string]:GCTD_E_CFG_UI},
    positions: {
        board: {x:100,y:100},
        mobX: 1200,
        mobYMin: 100,
        mobYMax: 600
    }
}
